//
//  refuseOrderViewController.m
//  Recycling
//
//  Created by jzd on 2018/5/29.
//  Copyright © 2018年 宋佳. All rights reserved.
//

#import "refuseOrderViewController.h"

@interface refuseOrderViewController ()<UITextViewDelegate>
@property (weak, nonatomic) IBOutlet UILabel *toastLab;
@property (weak, nonatomic) IBOutlet UITextView *reasonTextV;

@end

@implementation refuseOrderViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = BGCOLOR;
    self.reasonTextV.layer.borderColor = [UIColor darkGrayColor].CGColor;

}
-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
//    [[SJNetWorkTool sharedTool].tasks makeObjectsPerformSelector:@selector(cancel)];
}
-(void)textViewDidChange:(UITextView *)textView{
    if (textView.text.length>0) {
        self.toastLab.hidden = YES;
    }else{
        self.toastLab.hidden = NO;
    }
}
//这个函数的最后一个参数text代表你每次输入的的那个字，所以：
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
    if ([text isEqualToString:@"\n"]){ //判断输入的字是否是回车，即按下return
        //在这里做你响应return键的代码
        [textView resignFirstResponder];
        return NO; //这里返回NO，就代表return键值失效，即页面上按下return，不会出现换行，如果为yes，则输入页面会换行
    }
    
    return YES;
}
- (IBAction)uploadOnClick:(UIButton *)sender {
    NSDictionary *dict = @{@"id":@(self.model.ID),
                             @"uid":@([UserInfoTool shareUserInfoTool].Info.ID)
                             };
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:dict];
    if (self.reasonTextV.text.length != 0) {
        [params setObject:self.reasonTextV.text forKey:@"note"];
    }
    [[SJNetWorkTool sharedTool]requestWithURLString:refuseOrder parameters:params method:POST callBack:^(id responseObject, NSError *error) {
        if (responseObject) {
            int code = [[responseObject objectForKey:@"Code"] intValue];
            if (code == 1) {
                SJLog(@"拒单成功");
                if (self.isSuccess) {
                    self.isSuccess(YES);
                }
            }else{
                SJLog(@"拒绝失败");
                if (self.isSuccess) {
                    self.isSuccess(NO);
                }
            }
        }else{
            if (self.isSuccess) {
                self.isSuccess(NO);
            }
        }
        [self dismissViewControllerAnimated:YES completion:nil];
    }];
}
-(void)dealloc{
    SJLog(@"refuseOrderViewController挂了");
}
@end
